<template>
  <div class="overlay">
    <div class="overlayDiv">
      <div class="cover">
        <img :src="DetailObj.poster" alt="" />
      </div>
      <!-- 介绍部分 -->
      <div class="moveInfo">
        <div class="title">
          {{ DetailObj.name }} &nbsp;
          <span v-if="DetailObj?.item?.name === '3D'">&nbsp;3D&nbsp;</span>
          <span v-else>&nbsp;2D&nbsp;</span>
        </div>
        <div class="type">{{ DetailObj.category }}</div>
        <div class="time">{{ handleTime(DetailObj.premiereAt) }}上映</div>
        <div class="country">
          {{ DetailObj.nation }} | {{ DetailObj.runtime }}分钟
        </div>
        <div class="introduce" :class="{ isAddHeight: isAddHeight }">
          <p>
            {{ DetailObj.synopsis }}
          </p>
          <div class="arrowDown" :class="{ isDown: isDown }" @click="arrowDown">
            <van-icon name="arrow-down" v-if="isAddHeight" />
            <van-icon name="arrow-up" v-else />
          </div>
        </div>
      </div>
      <div style="height: 15px; background: rgb(218, 215, 215)"></div>
      <!-- 演职人员 -->
      <div class="performer">
        <h5>演职人员</h5>
        <div class="img">
          <van-swipe :loop="false" :width="85" :show-indicators="false">
            <van-swipe-item
              v-for="(obj, index) in DetailObj.actors"
              :key="index">
              <div class="tabs">
                <img :src="obj.avatarAddress" alt="" />
                <div class="name">
                  {{ obj.name }}
                  <p>{{ obj.role }}</p>
                </div>
              </div>
            </van-swipe-item>
          </van-swipe>
        </div>
      </div>
      <div style="height: 15px; background: rgb(218, 215, 215)"></div>
      <!-- 剧照 -->
      <div class="stills">
        <div class="top">
          <div class="left">剧照</div>
          <div class="right">全部(5)<van-icon name="arrow" size="4px" /></div>
        </div>
        <div class="img">
          <van-swipe :loop="false" :width="150" :show-indicators="false">
            <van-swipe-item
              v-for="(item, index) in DetailObj.photos"
              :key="index">
              <div class="tabs">
                <img :src="item" alt="" />
              </div>
            </van-swipe-item>
          </van-swipe>
        </div>
        <button class="btn">选座购票</button>
      </div>
      <div class="back" :class="{ isShowBg: isShowBg, ShowBg: ShowBg }">
        <div class="left">
          <van-icon
            name="arrow-left"
            class="arrow-left"
            size="20px"
            @click="$router.go(-1)" />
        </div>
        <div class="right" v-if="isShowBg || ShowBg">{{ DetailObj.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { getFilmDetail } from '@/api/movieApi'
import dayjs from 'dayjs'

export default {
  name: 'MoveDetail',
  data() {
    return {
      isAddHeight: false,
      isDown: false,
      DetailObj: {},
      isShowBg: false,
      ShowBg: false
    }
  },
  mounted() {
    getFilmDetail(this.$route.params.moveId).then((res) => {
      this.DetailObj = res.data.film
    })
    this.lisentScroll()
  },
  methods: {
    // 展开摘要
    arrowDown() {
      this.isAddHeight = !this.isAddHeight
      this.isDown = !this.isDown
    },
    // 处理时间戳
    handleTime(time) {
      return dayjs(time).format('YYYY-MM-DD')
    },
    // 监听滚动事件
    lisentScroll() {
      document.addEventListener('scroll', () => {
        if (window.pageYOffset > 120) {
          this.isShowBg = true
        } else if (window.pageYOffset < 120 && this.isShowBg) {
          this.ShowBg = true
          this.isShowBg = false
          setTimeout(() => {
            this.ShowBg = false
          }, 1000)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.overlay {
  position: absolute;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
}
.cover {
  background: #fff;
  width: 100vw;
  height: 210px;
  position: relative;
  z-index: -999;
  img {
    width: 100%;
  }
}
.moveInfo {
  background: #fff;
  padding: 10px;
  font-size: 13px;
  color: #797d82;
  .title {
    font-size: 18px;
    color: #000;
    span {
      font-size: 14px;
      background: rgb(192, 191, 191);
      border-radius: 5px;
      color: #fff;
    }
  }
  .type,
  .time,
  .country {
    margin: 5px 0;
  }
  .isAddHeight {
    height: 100% !important;
  }
  .isDown {
    transition: all 1s linear;
    top: (100%-20px) !important;
  }
  .introduce {
    position: relative;
    margin-top: 15px;
    overflow: hidden;
    height: 65px;
    p {
      padding-bottom: 30px;
    }
    .arrowDown {
      position: absolute;
      top: 35px;
      height: 30px;
      width: 100vw;
      background: #fff;
      text-align: center;
      line-height: 30px;
    }
  }
}
.performer {
  background: #fff;
  padding-left: 10px;
  h5 {
    height: 52px;
    line-height: 52px;
    font-size: 16px;
    font-weight: 400;
  }
  .van-swipe-item {
    margin-right: 30px;
  }
  .tabs {
    width: 100px;
    height: 162px;
    img {
      width: 100%;
      height: 117px;
    }
    .name {
      text-align: center;
      p {
        font-size: 10px;
        color: #797d82;
      }
    }
  }
}
.stills {
  background: #fff;
  padding-bottom: 90px;
  .top {
    display: flex;
    justify-content: space-between;
    height: 52px;
    line-height: 52px;
    padding: 0 10px;
    .left {
      font-size: 16px;
    }
    .right {
      font-size: 13px;
      color: #797d82;
    }
  }
  .img {
    padding-left: 10px;
    img {
      width: 150px;
      height: 85px;
    }
    .van-swipe-item {
      margin-right: 10px;
    }
  }
  .btn {
    width: 100vw;
    height: 49px;
    line-height: 49px;
    position: fixed;
    bottom: 0;
    text-align: center;
    color: #fff;
    background: #ff5f16;
    border: none;
  }
}
.back {
  position: fixed;
  width: 100vw;
  top: 0;
  display: flex;
  height: 44px;
  align-items: center;
  justify-content: space-between;
  z-index: 9999;

  .right {
    flex: 5;
    text-align: center;
    font-size: 17px;
  }
  .left {
    margin-left: 5px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    text-align: center;
    line-height: 34px;
    background: #fff;
    opacity: 0.5;
  }
}
.isShowBg {
  background: #fff;
  transition: all 1s linear;
}
.ShowBg {
  background: transparent;
  transition: all 1s linear;
}
</style>
